/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.threads;

/**
 *
 * @author andersonribeiro
 */
public class PingPong extends Thread {

    private String palavra;
    private int delay;

    public PingPong(String palavra, int delay) {
        this.palavra = palavra;
        this.delay = delay;
    }

    @Override
    public void run() {

        try{
            for(;;) {
                System.out.print(palavra + "\n");
                Thread.sleep(delay);
            }
        }catch(Exception e) {
            System.err.println("Erro");
            return;
        }
    }

    public static void main(String[] args) {

        PingPong ping = new PingPong("ping", 500);
        ping.start();
        PingPong pong = new PingPong("PONG", 1000);
        pong.start();
        
    }

}
